
cfgCatStepFormUi = Ext.extend(Ext.form.FormPanel, {

	region: 'center',
	autoScroll: true,
	style: 'overflow-x: hidden;',
	height: 460,
	id: 'cfgCatStepForm',
	title: 'Secuencia de Catalogos',
	frame: true,
	border: false,
	defaultType: 'textfield',
    initComponent: function(arguments) {
    	
        this.items = [
			{
				xtype: 'tbspacer',
				height: 10
			},
            {
            	xtype: 'container',
            	layout: 'column',
            	items:[
            	{
            		xtype: 'fieldset',
			    	style: 'padding: 10px',
            		title: 'Configuraci&oacute;n General',
					defaultType: 'textfield',
            		items: [
			            {
			                fieldLabel: 'titulo general',
							maskRe     : /[a-z ]/i,
							anchor: '100%',
							id: 'nbTitle',
			                allowBlank:false
			            },
       	 				{
							xtype: 'checkbox',
            				id:'isAnidate',
			            	fieldLabel: '&iquest; es inserci&oacute; anidada ?'
			    		},
       	 				{
							xtype: 'label',
							width: 200,
							style: 'font-size: 12px;',
			            	text: 'debe verse en ...'
			    		},
						{
							xtype: 'tbspacer',
							height: 10
						},
						new Ext.form.ComboBox({
			            	fieldLabel: 'modulo',
				            id:'cmbModule',
				            triggerAction: 'all',
				            width: 200,
			   				valueField: 'id',
			    			displayField: 'name',
			                allowBlank:false,
				            store: new Ext.data.JsonStore({
			   					url: 'admCat.do?method=getCombo&tpCombo=modules',
			   					root: 'data',     
			  					fields: ['id','name'] 
							}),
							listeners:{ 
							'select' : function(cmb,record,index){ 
								     subModuleCmb.clearValue();
								     subModuleCmb.enable();   
								     subModuleDs.load({          
								         params:{  
								             module:record.get('id')  
								         }  
								     });  
								 }
							}
				        }),
						subModuleCmb = new Ext.form.ComboBox({
							disabled: true, 
			            	fieldLabel: 'sub modulo',
			            	mode: 'local',       
			                allowBlank:false,
				            id:'cmbSubModule',
				            triggerAction: 'all',
				            width: 200,
			   				valueField: 'id',
			    			displayField: 'name',
				            store: subModuleDs = new Ext.data.JsonStore({
			   					url:  'admCat.do?method=getCombo&tpCombo=subModules',
			   					root: 'data',     
			  					fields: ['id','name'] 
							}),
							listeners:{ 
							'select' : function(cmb,record,index){
									functionCmb.enable();
								    functionDs.load({          
								         params:{  
								             subModule:record.get('id'),
								             module:Ext.getCmp('cmbModule').getValue()  
								         }  
								     });  
								}
							}
				        }),	        
						functionCmb = new Ext.form.ComboBox({
							disabled: true, 
			            	fieldLabel: 'funci&oacute;n',
			            	mode: 'local',      //Step 2  
				            id:'cmbFunction',
				            triggerAction: 'all',
				            width: 200,
			   				valueField: 'id',
			    			displayField: 'name',
				            store: functionDs = new Ext.data.JsonStore({
			   					url:  'admCat.do?method=getCombo&tpCombo=functions',
			   					root: 'data',     
			  					fields: ['id','name'] 
							}),
							listeners:{ 
							'select' : function(){
								}
							}
				        }),	        
				        {
			                xtype: 'tbspacer',
			            	height: 5
			            },
			            {
			                xtype: 'button',
							style: 'padding-left: 170px;',
			                text:'agregar configuraci&oacute;n',
			                iconCls: 'silk-accept',
							handler: function(){
								var x = Ext.getCmp('nbTitle').getValue();
								if(x != ""){
									Ext.Ajax.request({
										method: 'POST',
									   	url: '/agvWeb/admCat.do?method=addStepsConfiguration',
										   success: function (response,conn){
												var responseData = Ext.util.JSON.decode(response.responseText);
												if(responseData.success){
													listViewStore.load();
													clearForm();
											   		Ext.Msg.show({
											            			 	title:'agv software',
											            			 	msg: 'El catalogo ha sido configurado exitosamente.', 
											            			 	buttons: Ext.Msg.OK, 
											            			 	icon: 'silk-accept' });
												} else {
											   		Ext.Msg.show({
											            			 	title:'agv software',
											            			 	msg: responseData.msg, 
											            			 	buttons: Ext.Msg.OK, 
											            			 	icon: 'silk-error' });
												}
										   },
									   params: { title: Ext.getCmp('nbTitle').getValue(),
									   					isAnidate:  Ext.getCmp('isAnidate').getValue(),
									   					module:  Ext.getCmp('cmbModule').getValue(),
									   					subModule:  Ext.getCmp('cmbSubModule').getValue(),
									   					func: Ext.getCmp('cmbFunction').getValue()
									   				  }
									});
								} else {
									   		Ext.Msg.show({
									            			 	title:'agv software',
									            			 	msg: 'Debe informar los campos requeridos', 
									            			 	buttons: Ext.Msg.OK, 
									            			 	icon: 'silk-error' });
								}
							}
			            }
            		]
            	},
				{
				    xtype: 'box',
			    	height: 250,
				    autoEl: {tag: 'img', src:'/agvWeb/ext/images/icons/fam/arrow_right_2.png'}
				},
				    {
				    	xtype: 'fieldset',
				    	width: 400,
				    	style: 'padding: 10px',
				    	layout: 'form',
				    	id:'paramForm',
				    	title: 'Secuencia de Catalogos',
						defaultType: 'textfield',
						labelWidth: 150,
				    	items: [
							new Ext.form.ComboBox({
            					fieldLabel: 'catalogo',
	            				id:'cmbCat',
	            				triggerAction: 'all',
	            				width: 200,
   								valueField: 'id',
    							displayField: 'name',
	            				store: vtypesDs = new Ext.data.JsonStore({
   									url:  'admCat.do?method=getCombo&tpCombo=catalogs',
   									root: 'data',     
  									fields: ['id','name'] 
								}),
								listeners:
									{ 
										'select' : function(cmb,record,index){
										}
									}
	       	 					}),
				    		{
								xtype: 'checkbox',
	            				id:'req',
				            	fieldLabel: '&iquest; es obligatorio ?'
				    		},
				    		{
								xtype: 'button',
								style: 'padding-left: 265px;',
								text: 'agregar paso',
								iconCls: 'silk-arrow-right',
								handler: function(){
									var x = Ext.getCmp('cmbCat').getValue();
									if(x != ""){
										Ext.Ajax.request({
											method: 'POST',
										   	url: '/agvWeb/admCat.do?method=addStep',
											   success: function (response,conn){
													var responseData = Ext.util.JSON.decode(response.responseText);
													
													if(responseData.success){
														listViewStore.load();
														clearParamForm();
													} else {
												   		Ext.Msg.show({
												            			 	title:'agv software',
												            			 	msg: responseData.msg, 
												            			 	buttons: Ext.Msg.OK, 
												            			 	icon: 'silk-error' });
													}
											   },
										   params: { name: Ext.getCmp('cmbCat').getValue(),
										   					required: Ext.getCmp('req').getValue()
										   				  }
										});
									} else {
										   		Ext.Msg.show({
										            			 	title:'agv software',
										            			 	msg: 'Debe informar los campos requeridos', 
										            			 	buttons: Ext.Msg.OK, 
										            			 	icon: 'silk-error' });
									}
								}
				    		}
				    	]
				    },
				{
				    xtype: 'box',
			    	height: 250,
				    autoEl: {tag: 'img', src:'/agvWeb/ext/images/icons/fam/arrow_right_2.png'}
				},
				
				    {
				    	xtype: 'fieldset',
				    	width: 400,
				    	style: 'padding: 10px',
				    	title: 'Secuencia Configurada',
			    		bbar: new Ext.Toolbar({
			    			buttonAlign: 'right',
			    			items:[
					        	{xtype: 'tbseparator'},
				    			{
									text: 'modificar',
									iconCls: 'silk-user-edit',
									handler: 
										function(){
											var x = listView.selected.elements.length;
											if(x == 0){
												Ext.Msg.show({
										            			 	title:'agv software',
										            			 	msg: 'Debe seleccionar un parametro', 
										            			 	buttons: Ext.Msg.OK, 
										            			 	icon: 'silk-error' });
											} else {
												var selectedItem = listView.selected.elements[0];
											}
										}					    				
				    			},
					        	{xtype: 'tbseparator'},
				    			{
									text: 'eliminar',
									iconCls: 'silk-delete',
									handler: 
										function(){
											var x = listView.selected.elements.length;
											if(x == 0){
												Ext.Msg.show({
										            			 	title:'agv software',
										            			 	msg: 'Debe seleccionar un parametro', 
										            			 	buttons: Ext.Msg.OK, 
										            			 	icon: 'silk-error' });
											} else {
												var y = listView.getSelectedRecords();
												var nm = y[0].data.name;

												Ext.Ajax.request({
													method: 'POST',
												   	url: '/agvWeb/admCat.do?method=deleteSteps',
													   success: function (response,conn){
															var responseData = Ext.util.JSON.decode(response.responseText);
															
															if(responseData.success){
																listViewStore.load();
															} else {
														   		Ext.Msg.show({
														            			 	title:'agv software',
														            			 	msg: responseData.msg, 
														            			 	buttons: Ext.Msg.OK, 
														            			 	icon: 'silk-error' });
															}
													   },
												   params: { name: nm}
												});
											}
										}					    				
				    			},
					        	{xtype: 'tbseparator'}
			    			]
			    		}),
				    	items:[
				    		listView = new Ext.list.ListView({
				    		singleSelect: true,
				    		autoScroll: true,
				    		reserveScrollOffset: true,
				    		store:  listViewStore = new Ext.data.JsonStore({
							    url: '/agvWeb/admCat.do?method=getSteps',
							    root: 'data',
							    fields: ['name', 'step','isReq']
							}),
							id: 'listView',
							columns: [{
						        header: 'Catalogo',
						        dataIndex: 'name'
						    },
						    {
						        header: 'es reqerido',
						        dataIndex: 'isReq'
						    },
						    {
						        header: 'paso',
						        dataIndex: 'step'
						    }
						    ]
						})
				    	]
				    }				
				
				
				]
            
            }];
        
			Ext.Ajax.request({
				method: 'POST',
			   	url: '/agvWeb/admCat.do?method=cleanSteps'
			});
            
        cfgCatStepFormUi.superclass.initComponent.call(this);
        
        
		function clearForm(){
			Ext.getCmp('cmbCat').setValue('');
			Ext.getCmp('req').setValue('');
			Ext.getCmp('nbTitle').setValue('');
			Ext.getCmp('isAnidate').setValue('');
		}
		
		function clearParamForm(){
			Ext.getCmp('cmbCat').setValue('');
			Ext.getCmp('req').setValue('');
		}
		
    }

});

cfgCatStepForm = Ext.extend(cfgCatStepFormUi, {
    initComponent: function(arguments) {
        cfgCatStepForm.superclass.initComponent.call(this);
    }
});


